<!DOCTYPE html><!--[if IE 8]><html class="no-js lt-ie9" lang="en" > <![endif]--><!--[if gt IE 8]><!--><html class="no-js" lang="en"><!--<![endif]--><head>
  <meta charset="utf-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  
  
  <link rel="canonical" href="https://sequelize.org/v3/docs/api/hooks/">
  <link rel="shortcut icon" href="/v3/favicon.ico">
  
  <title>Hooks - Sequelize | The Node.js / io.js ORM for PostgreSQL, MySQL, SQLite and MSSQL</title>
  <link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Lato:400,700|Roboto+Slab:400,700|Inconsolata:400,700">

  <link rel="stylesheet" href="/v3/css/theme.css">
  <link rel="stylesheet" href="/v3/css/theme_extra.css">
  <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/10.5.0/styles/github.min.css">
  <link href="/v3/css/custom.css" rel="stylesheet">
  
  <script>
    // Current page data
    var mkdocs_page_name = "Hooks";
    var mkdocs_page_input_path = "api/hooks.md";
    var mkdocs_page_url = "/api/hooks/";
  </script>
  
  <script src="/v3/js/jquery-2.1.1.min.js" defer=""></script>
  <script src="/v3/js/modernizr-2.8.3.min.js" defer=""></script>
  <script src="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/10.5.0/highlight.min.js"></script>
  <script>hljs.initHighlightingOnLoad();</script> 
<meta name="robots" content="noindex"></head>

<body class="wy-body-for-nav" role="document">

  <div class="wy-grid-for-nav">

    
    <nav data-toggle="wy-nav-shift" class="wy-nav-side stickynav">
    <div class="wy-side-scroll">
      <div class="wy-side-nav-search">
        <a href="/v3" class="icon icon-home"> Sequelize | The Node.js / io.js ORM for PostgreSQL, MySQL, SQLite and MSSQL</a>
        <div role="search">
  <form id="rtd-search-form" class="wy-form" action="/v3/search.html" method="get">
      <input type="text" name="q" placeholder="Search docs" title="Type search term here">
  </form>
</div>
      </div>

      <div class="wy-menu wy-menu-vertical" data-spy="affix" role="navigation" aria-label="main navigation">
                <ul>
                    <li class="toctree-l1"><a class="reference internal" href="/v3">Home</a>
                    </li>
                </ul>
                <p class="caption"><span class="caption-text">Documentation</span></p>
                <ul>
                    <li class="toctree-l1"><a class="reference internal" href="/v3/docs/getting-started/">Getting Started</a>
                    </li>
                    <li class="toctree-l1"><a class="reference internal" href="/v3/docs/schema/">Working with table schemas</a>
                    </li>
                    <li class="toctree-l1"><a class="reference internal" href="#">Models</a>
    <ul>
                <li class="toctree-l2"><a class="reference internal" href="/v3/docs/models-definition/">Definition</a>
                </li>
                <li class="toctree-l2"><a class="reference internal" href="/v3/docs/models-usage/">Usage</a>
                </li>
    </ul>
                    </li>
                    <li class="toctree-l1"><a class="reference internal" href="/v3/docs/querying/">Querying</a>
                    </li>
                    <li class="toctree-l1"><a class="reference internal" href="/v3/docs/scopes/">Scopes</a>
                    </li>
                    <li class="toctree-l1"><a class="reference internal" href="/v3/docs/instances/">Instances</a>
                    </li>
                    <li class="toctree-l1"><a class="reference internal" href="/v3/docs/associations/">Relations / Associations</a>
                    </li>
                    <li class="toctree-l1"><a class="reference internal" href="/v3/docs/hooks/">Hooks</a>
                    </li>
                    <li class="toctree-l1"><a class="reference internal" href="/v3/docs/transactions/">Transactions</a>
                    </li>
                    <li class="toctree-l1"><a class="reference internal" href="/v3/docs/legacy/">Working with legacy tables</a>
                    </li>
                    <li class="toctree-l1"><a class="reference internal" href="/v3/docs/raw-queries/">Raw queries</a>
                    </li>
                    <li class="toctree-l1"><a class="reference internal" href="/v3/docs/migrations/">Migrations</a>
                    </li>
                </ul>
                <p class="caption"><span class="caption-text">API</span></p>
                <ul class="current">
                    <li class="toctree-l1"><a class="reference internal" href="/v3/api/sequelize/">Sequelize</a>
                    </li>
                    <li class="toctree-l1"><a class="reference internal" href="/v3/api/model/">Model</a>
                    </li>
                    <li class="toctree-l1"><a class="reference internal" href="/v3/api/instance/">Instance</a>
                    </li>
                    <li class="toctree-l1"><a class="reference internal" href="#">Associations</a>
    <ul>
                <li class="toctree-l2"><a class="reference internal" href="/v3/api/associations/">Overview</a>
                </li>
                <li class="toctree-l2"><a class="reference internal" href="/v3/api/associations/belongs-to/">BelongsTo (1:1)</a>
                </li>
                <li class="toctree-l2"><a class="reference internal" href="/v3/api/associations/has-one/">HasOne (1:1)</a>
                </li>
                <li class="toctree-l2"><a class="reference internal" href="/v3/api/associations/has-many/">HasMany (1:m)</a>
                </li>
                <li class="toctree-l2"><a class="reference internal" href="/v3/api/associations/belongs-to-many/">BelongsToMany (n:m)</a>
                </li>
    </ul>
                    </li>
                    <li class="toctree-l1 current"><a class="reference internal current" href="./">Hooks</a>
    <ul class="current">
    <li class="toctree-l2"><a class="reference internal" href="#addhookhooktype-name-fn">addHook(hooktype, [name], fn)</a>
    </li>
    <li class="toctree-l2"><a class="reference internal" href="#removehookhooktype-name">removeHook(hookType, name)</a>
    </li>
    <li class="toctree-l2"><a class="reference internal" href="#hashookhooktype">hasHook(hookType)</a>
    </li>
    <li class="toctree-l2"><a class="reference internal" href="#beforevalidatename-fn">beforeValidate(name, fn)</a>
    </li>
    <li class="toctree-l2"><a class="reference internal" href="#aftervalidatename-fn">afterValidate(name, fn)</a>
    </li>
    <li class="toctree-l2"><a class="reference internal" href="#beforecreatename-fn">beforeCreate(name, fn)</a>
    </li>
    <li class="toctree-l2"><a class="reference internal" href="#aftercreatename-fn">afterCreate(name, fn)</a>
    </li>
    <li class="toctree-l2"><a class="reference internal" href="#beforedestroyname-fn">beforeDestroy(name, fn)</a>
    </li>
    <li class="toctree-l2"><a class="reference internal" href="#afterdestroyname-fn">afterDestroy(name, fn)</a>
    </li>
    <li class="toctree-l2"><a class="reference internal" href="#beforerestorename-fn">beforeRestore(name, fn)</a>
    </li>
    <li class="toctree-l2"><a class="reference internal" href="#afterrestorename-fn">afterRestore(name, fn)</a>
    </li>
    <li class="toctree-l2"><a class="reference internal" href="#beforeupdatename-fn">beforeUpdate(name, fn)</a>
    </li>
    <li class="toctree-l2"><a class="reference internal" href="#afterupdatename-fn">afterUpdate(name, fn)</a>
    </li>
    <li class="toctree-l2"><a class="reference internal" href="#beforebulkcreatename-fn">beforeBulkCreate(name, fn)</a>
    </li>
    <li class="toctree-l2"><a class="reference internal" href="#afterbulkcreatename-fn">afterBulkCreate(name, fn)</a>
    </li>
    <li class="toctree-l2"><a class="reference internal" href="#beforebulkdestroyname-fn">beforeBulkDestroy(name, fn)</a>
    </li>
    <li class="toctree-l2"><a class="reference internal" href="#afterbulkdestroyname-fn">afterBulkDestroy(name, fn)</a>
    </li>
    <li class="toctree-l2"><a class="reference internal" href="#beforebulkrestorename-fn">beforeBulkRestore(name, fn)</a>
    </li>
    <li class="toctree-l2"><a class="reference internal" href="#afterbulkrestorename-fn">afterBulkRestore(name, fn)</a>
    </li>
    <li class="toctree-l2"><a class="reference internal" href="#beforebulkupdatename-fn">beforeBulkUpdate(name, fn)</a>
    </li>
    <li class="toctree-l2"><a class="reference internal" href="#afterbulkupdatename-fn">afterBulkUpdate(name, fn)</a>
    </li>
    <li class="toctree-l2"><a class="reference internal" href="#beforefindname-fn">beforeFind(name, fn)</a>
    </li>
    <li class="toctree-l2"><a class="reference internal" href="#beforefindafterexpandincludeallname-fn">beforeFindAfterExpandIncludeAll(name, fn)</a>
    </li>
    <li class="toctree-l2"><a class="reference internal" href="#beforefindafteroptionsname-fn">beforeFindAfterOptions(name, fn)</a>
    </li>
    <li class="toctree-l2"><a class="reference internal" href="#afterfindname-fn">afterFind(name, fn)</a>
    </li>
    <li class="toctree-l2"><a class="reference internal" href="#beforedefinename-fn">beforeDefine(name, fn)</a>
    </li>
    <li class="toctree-l2"><a class="reference internal" href="#afterdefinename-fn">afterDefine(name, fn)</a>
    </li>
    <li class="toctree-l2"><a class="reference internal" href="#beforeinitname-fn">beforeInit(name, fn)</a>
    </li>
    <li class="toctree-l2"><a class="reference internal" href="#afterinitname-fn">afterInit(name, fn)</a>
    </li>
    <li class="toctree-l2"><a class="reference internal" href="#beforesyncname-fn">beforeSync(name, fn)</a>
    </li>
    <li class="toctree-l2"><a class="reference internal" href="#aftersyncname-fn">afterSync(name, fn)</a>
    </li>
    <li class="toctree-l2"><a class="reference internal" href="#beforebulksyncname-fn">beforeBulkSync(name, fn)</a>
    </li>
    <li class="toctree-l2"><a class="reference internal" href="#afterbulksync">afterBulkSync</a>
    </li>
    </ul>
                    </li>
                    <li class="toctree-l1"><a class="reference internal" href="/v3/api/transaction/">Transaction</a>
                    </li>
                    <li class="toctree-l1"><a class="reference internal" href="/v3/api/datatypes/">Datatypes</a>
                    </li>
                    <li class="toctree-l1"><a class="reference internal" href="/v3/api/deferrable/">Deferrable</a>
                    </li>
                    <li class="toctree-l1"><a class="reference internal" href="/v3/api/errors/">Errors</a>
                    </li>
                </ul>
                <p class="caption"><span class="caption-text">Misc</span></p>
                <ul>
                    <li class="toctree-l1"><a class="reference internal" href="/v3/changelog/">Changelog</a>
                    </li>
                    <li class="toctree-l1"><a class="reference internal" href="/v3/imprint/">Imprint</a>
                    </li>
                </ul>
      </div>
    </div>
    </nav>

    <section data-toggle="wy-nav-shift" class="wy-nav-content-wrap">

      
      <nav class="wy-nav-top" role="navigation" aria-label="top navigation">
        <i data-toggle="wy-nav-top" class="fa fa-bars"></i>
        <a href="/v3">Sequelize | The Node.js / io.js ORM for PostgreSQL, MySQL, SQLite and MSSQL</a>
      </nav>

      
      <div class="wy-nav-content">
        <div class="rst-content">
          <div role="navigation" aria-label="breadcrumbs navigation">
  <ul class="wy-breadcrumbs">
    <li><a href="/v3">Docs</a> »</li>
    
      
        
          <li>API »</li>
        
      
    
    <li>Hooks</li>
    <li class="wy-breadcrumbs-aside">
      
        <a href="https://github.com/sequelize/sequelize/edit/master/docs/api/hooks.md" class="icon icon-github"> Edit on GitHub</a>
      
    </li>
  </ul>
  
  <hr>
</div>

          <div role="main">
            <div class="section">
              
                <p><a name="hooks"></a></p>
<h1 id="mixin-hooks">Mixin Hooks</h1>
<p><a href="https://github.com/sequelize/sequelize/blob/3e5b8772ef75169685fc96024366bca9958fee63/lib/hooks.js#L39">View code</a></p>
<p>Hooks are function that are called before and after  (bulk-) creation/updating/deletion and validation. Hooks can be added to you models in three ways:</p>
<ol>
<li>By specifying them as options in <code>sequelize.define</code></li>
<li>By calling <code>hook()</code> with a string and your hook handler function</li>
<li>By calling the function with the same name as the hook you want</li>
</ol>
<pre><code class="language-js">// Method 1
sequelize.define(name, { attributes }, {
  hooks: {
    beforeBulkCreate: function () {
      // can be a single function
    },
    beforeValidate: [
      function () {},
      function() {} // Or an array of several
    ]
  }
})

// Method 2
Model.hook('afterDestroy', function () {})

// Method 3
Model.afterBulkUpdate(function () {})
</code></pre>
<p><strong>See:</strong></p>
<ul>
<li><a href="./sequelize#define">Sequelize#define</a></li>
</ul>
<hr>
<p><a name="addhook"></a></p>
<h2 id="addhookhooktype-name-fn"><code>addHook(hooktype, [name], fn)</code></h2>
<p><a href="https://github.com/sequelize/sequelize/blob/3e5b8772ef75169685fc96024366bca9958fee63/lib/hooks.js#L160">View code</a></p>
<p>Add a hook to the model</p>
<p><strong>Params:</strong></p>
<table>
<thead>
<tr>
<th>Name</th>
<th>Type</th>
<th>Description</th>
</tr>
</thead>
<tbody>
<tr>
<td>hooktype</td>
<td>String</td>
<td></td>
</tr>
<tr>
<td>[name]</td>
<td>String</td>
<td>Provide a name for the hook function. It can be used to remove the hook later or to order hooks based on some sort of priority system in the future.</td>
</tr>
<tr>
<td>fn</td>
<td>Function</td>
<td>The hook function</td>
</tr>
</tbody>
</table>
<p><strong>Aliases:</strong> hook</p>
<hr>
<p><a name="removehook"></a></p>
<h2 id="removehookhooktype-name"><code>removeHook(hookType, name)</code></h2>
<p><a href="https://github.com/sequelize/sequelize/blob/3e5b8772ef75169685fc96024366bca9958fee63/lib/hooks.js#L179">View code</a></p>
<p>Remove hook from the model</p>
<p><strong>Params:</strong></p>
<table>
<thead>
<tr>
<th>Name</th>
<th>Type</th>
<th>Description</th>
</tr>
</thead>
<tbody>
<tr>
<td>hookType</td>
<td>String</td>
<td></td>
</tr>
<tr>
<td>name</td>
<td>String</td>
<td></td>
</tr>
</tbody>
</table>
<hr>
<p><a name="hashook"></a></p>
<h2 id="hashookhooktype"><code>hasHook(hookType)</code></h2>
<p><a href="https://github.com/sequelize/sequelize/blob/3e5b8772ef75169685fc96024366bca9958fee63/lib/hooks.js#L205">View code</a></p>
<p>Check whether the mode has any hooks of this type</p>
<p><strong>Params:</strong></p>
<table>
<thead>
<tr>
<th>Name</th>
<th>Type</th>
<th>Description</th>
</tr>
</thead>
<tbody>
<tr>
<td>hookType</td>
<td>String</td>
<td></td>
</tr>
</tbody>
</table>
<p><strong>Aliases:</strong> hasHooks</p>
<hr>
<p><a name="beforevalidate"></a></p>
<h2 id="beforevalidatename-fn"><code>beforeValidate(name, fn)</code></h2>
<p><a href="https://github.com/sequelize/sequelize/blob/3e5b8772ef75169685fc96024366bca9958fee63/lib/hooks.js#L218">View code</a></p>
<p>A hook that is run before validation</p>
<p><strong>Params:</strong></p>
<table>
<thead>
<tr>
<th>Name</th>
<th>Type</th>
<th>Description</th>
</tr>
</thead>
<tbody>
<tr>
<td>name</td>
<td>String</td>
<td></td>
</tr>
<tr>
<td>fn</td>
<td>Function</td>
<td>A callback function that is called with instance, options</td>
</tr>
</tbody>
</table>
<hr>
<p><a name="aftervalidate"></a></p>
<h2 id="aftervalidatename-fn"><code>afterValidate(name, fn)</code></h2>
<p><a href="https://github.com/sequelize/sequelize/blob/3e5b8772ef75169685fc96024366bca9958fee63/lib/hooks.js#L225">View code</a></p>
<p>A hook that is run after validation</p>
<p><strong>Params:</strong></p>
<table>
<thead>
<tr>
<th>Name</th>
<th>Type</th>
<th>Description</th>
</tr>
</thead>
<tbody>
<tr>
<td>name</td>
<td>String</td>
<td></td>
</tr>
<tr>
<td>fn</td>
<td>Function</td>
<td>A callback function that is called with instance, options</td>
</tr>
</tbody>
</table>
<hr>
<p><a name="beforecreate"></a></p>
<h2 id="beforecreatename-fn"><code>beforeCreate(name, fn)</code></h2>
<p><a href="https://github.com/sequelize/sequelize/blob/3e5b8772ef75169685fc96024366bca9958fee63/lib/hooks.js#L232">View code</a></p>
<p>A hook that is run before creating a single instance</p>
<p><strong>Params:</strong></p>
<table>
<thead>
<tr>
<th>Name</th>
<th>Type</th>
<th>Description</th>
</tr>
</thead>
<tbody>
<tr>
<td>name</td>
<td>String</td>
<td></td>
</tr>
<tr>
<td>fn</td>
<td>Function</td>
<td>A callback function that is called with attributes, options</td>
</tr>
</tbody>
</table>
<hr>
<p><a name="aftercreate"></a></p>
<h2 id="aftercreatename-fn"><code>afterCreate(name, fn)</code></h2>
<p><a href="https://github.com/sequelize/sequelize/blob/3e5b8772ef75169685fc96024366bca9958fee63/lib/hooks.js#L239">View code</a></p>
<p>A hook that is run after creating a single instance</p>
<p><strong>Params:</strong></p>
<table>
<thead>
<tr>
<th>Name</th>
<th>Type</th>
<th>Description</th>
</tr>
</thead>
<tbody>
<tr>
<td>name</td>
<td>String</td>
<td></td>
</tr>
<tr>
<td>fn</td>
<td>Function</td>
<td>A callback function that is called with attributes, options</td>
</tr>
</tbody>
</table>
<hr>
<p><a name="beforedestroy"></a></p>
<h2 id="beforedestroyname-fn"><code>beforeDestroy(name, fn)</code></h2>
<p><a href="https://github.com/sequelize/sequelize/blob/3e5b8772ef75169685fc96024366bca9958fee63/lib/hooks.js#L248">View code</a></p>
<p>A hook that is run before destroying a single instance</p>
<p><strong>Params:</strong></p>
<table>
<thead>
<tr>
<th>Name</th>
<th>Type</th>
<th>Description</th>
</tr>
</thead>
<tbody>
<tr>
<td>name</td>
<td>String</td>
<td></td>
</tr>
<tr>
<td>fn</td>
<td>Function</td>
<td>A callback function that is called with instance, options</td>
</tr>
</tbody>
</table>
<p><strong>Aliases:</strong> beforeDelete</p>
<hr>
<p><a name="afterdestroy"></a></p>
<h2 id="afterdestroyname-fn"><code>afterDestroy(name, fn)</code></h2>
<p><a href="https://github.com/sequelize/sequelize/blob/3e5b8772ef75169685fc96024366bca9958fee63/lib/hooks.js#L257">View code</a></p>
<p>A hook that is run after destroying a single instance</p>
<p><strong>Params:</strong></p>
<table>
<thead>
<tr>
<th>Name</th>
<th>Type</th>
<th>Description</th>
</tr>
</thead>
<tbody>
<tr>
<td>name</td>
<td>String</td>
<td></td>
</tr>
<tr>
<td>fn</td>
<td>Function</td>
<td>A callback function that is called with instance, options</td>
</tr>
</tbody>
</table>
<p><strong>Aliases:</strong> afterDelete</p>
<hr>
<p><a name="beforerestore"></a></p>
<h2 id="beforerestorename-fn"><code>beforeRestore(name, fn)</code></h2>
<p><a href="https://github.com/sequelize/sequelize/blob/3e5b8772ef75169685fc96024366bca9958fee63/lib/hooks.js#L265">View code</a></p>
<p>A hook that is run before restoring a single instance</p>
<p><strong>Params:</strong></p>
<table>
<thead>
<tr>
<th>Name</th>
<th>Type</th>
<th>Description</th>
</tr>
</thead>
<tbody>
<tr>
<td>name</td>
<td>String</td>
<td></td>
</tr>
<tr>
<td>fn</td>
<td>Function</td>
<td>A callback function that is called with instance, options</td>
</tr>
</tbody>
</table>
<hr>
<p><a name="afterrestore"></a></p>
<h2 id="afterrestorename-fn"><code>afterRestore(name, fn)</code></h2>
<p><a href="https://github.com/sequelize/sequelize/blob/3e5b8772ef75169685fc96024366bca9958fee63/lib/hooks.js#L273">View code</a></p>
<p>A hook that is run after restoring a single instance</p>
<p><strong>Params:</strong></p>
<table>
<thead>
<tr>
<th>Name</th>
<th>Type</th>
<th>Description</th>
</tr>
</thead>
<tbody>
<tr>
<td>name</td>
<td>String</td>
<td></td>
</tr>
<tr>
<td>fn</td>
<td>Function</td>
<td>A callback function that is called with instance, options</td>
</tr>
</tbody>
</table>
<hr>
<p><a name="beforeupdate"></a></p>
<h2 id="beforeupdatename-fn"><code>beforeUpdate(name, fn)</code></h2>
<p><a href="https://github.com/sequelize/sequelize/blob/3e5b8772ef75169685fc96024366bca9958fee63/lib/hooks.js#L280">View code</a></p>
<p>A hook that is run before updating a single instance</p>
<p><strong>Params:</strong></p>
<table>
<thead>
<tr>
<th>Name</th>
<th>Type</th>
<th>Description</th>
</tr>
</thead>
<tbody>
<tr>
<td>name</td>
<td>String</td>
<td></td>
</tr>
<tr>
<td>fn</td>
<td>Function</td>
<td>A callback function that is called with instance, options</td>
</tr>
</tbody>
</table>
<hr>
<p><a name="afterupdate"></a></p>
<h2 id="afterupdatename-fn"><code>afterUpdate(name, fn)</code></h2>
<p><a href="https://github.com/sequelize/sequelize/blob/3e5b8772ef75169685fc96024366bca9958fee63/lib/hooks.js#L287">View code</a></p>
<p>A hook that is run after updating a single instance</p>
<p><strong>Params:</strong></p>
<table>
<thead>
<tr>
<th>Name</th>
<th>Type</th>
<th>Description</th>
</tr>
</thead>
<tbody>
<tr>
<td>name</td>
<td>String</td>
<td></td>
</tr>
<tr>
<td>fn</td>
<td>Function</td>
<td>A callback function that is called with instance, options</td>
</tr>
</tbody>
</table>
<hr>
<p><a name="beforebulkcreate"></a></p>
<h2 id="beforebulkcreatename-fn"><code>beforeBulkCreate(name, fn)</code></h2>
<p><a href="https://github.com/sequelize/sequelize/blob/3e5b8772ef75169685fc96024366bca9958fee63/lib/hooks.js#L294">View code</a></p>
<p>A hook that is run before creating instances in bulk</p>
<p><strong>Params:</strong></p>
<table>
<thead>
<tr>
<th>Name</th>
<th>Type</th>
<th>Description</th>
</tr>
</thead>
<tbody>
<tr>
<td>name</td>
<td>String</td>
<td></td>
</tr>
<tr>
<td>fn</td>
<td>Function</td>
<td>A callback function that is called with instances, options</td>
</tr>
</tbody>
</table>
<hr>
<p><a name="afterbulkcreate"></a></p>
<h2 id="afterbulkcreatename-fn"><code>afterBulkCreate(name, fn)</code></h2>
<p><a href="https://github.com/sequelize/sequelize/blob/3e5b8772ef75169685fc96024366bca9958fee63/lib/hooks.js#L301">View code</a></p>
<p>A hook that is run after creating instances in bulk</p>
<p><strong>Params:</strong></p>
<table>
<thead>
<tr>
<th>Name</th>
<th>Type</th>
<th>Description</th>
</tr>
</thead>
<tbody>
<tr>
<td>name</td>
<td>String</td>
<td></td>
</tr>
<tr>
<td>fn</td>
<td>Function</td>
<td>A callback function that is called with instances, options</td>
</tr>
</tbody>
</table>
<hr>
<p><a name="beforebulkdestroy"></a></p>
<h2 id="beforebulkdestroyname-fn"><code>beforeBulkDestroy(name, fn)</code></h2>
<p><a href="https://github.com/sequelize/sequelize/blob/3e5b8772ef75169685fc96024366bca9958fee63/lib/hooks.js#L310">View code</a></p>
<p>A hook that is run before destroying instances in bulk</p>
<p><strong>Params:</strong></p>
<table>
<thead>
<tr>
<th>Name</th>
<th>Type</th>
<th>Description</th>
</tr>
</thead>
<tbody>
<tr>
<td>name</td>
<td>String</td>
<td></td>
</tr>
<tr>
<td>fn</td>
<td>Function</td>
<td>A callback function that is called with options</td>
</tr>
</tbody>
</table>
<p><strong>Aliases:</strong> beforeBulkDelete</p>
<hr>
<p><a name="afterbulkdestroy"></a></p>
<h2 id="afterbulkdestroyname-fn"><code>afterBulkDestroy(name, fn)</code></h2>
<p><a href="https://github.com/sequelize/sequelize/blob/3e5b8772ef75169685fc96024366bca9958fee63/lib/hooks.js#L319">View code</a></p>
<p>A hook that is run after destroying instances in bulk</p>
<p><strong>Params:</strong></p>
<table>
<thead>
<tr>
<th>Name</th>
<th>Type</th>
<th>Description</th>
</tr>
</thead>
<tbody>
<tr>
<td>name</td>
<td>String</td>
<td></td>
</tr>
<tr>
<td>fn</td>
<td>Function</td>
<td>A callback function that is called with options</td>
</tr>
</tbody>
</table>
<p><strong>Aliases:</strong> afterBulkDelete</p>
<hr>
<p><a name="beforebulkrestore"></a></p>
<h2 id="beforebulkrestorename-fn"><code>beforeBulkRestore(name, fn)</code></h2>
<p><a href="https://github.com/sequelize/sequelize/blob/3e5b8772ef75169685fc96024366bca9958fee63/lib/hooks.js#L327">View code</a></p>
<p>A hook that is run before restoring instances in bulk</p>
<p><strong>Params:</strong></p>
<table>
<thead>
<tr>
<th>Name</th>
<th>Type</th>
<th>Description</th>
</tr>
</thead>
<tbody>
<tr>
<td>name</td>
<td>String</td>
<td></td>
</tr>
<tr>
<td>fn</td>
<td>Function</td>
<td>A callback function that is called with options</td>
</tr>
</tbody>
</table>
<hr>
<p><a name="afterbulkrestore"></a></p>
<h2 id="afterbulkrestorename-fn"><code>afterBulkRestore(name, fn)</code></h2>
<p><a href="https://github.com/sequelize/sequelize/blob/3e5b8772ef75169685fc96024366bca9958fee63/lib/hooks.js#L335">View code</a></p>
<p>A hook that is run after restoring instances in bulk</p>
<p><strong>Params:</strong></p>
<table>
<thead>
<tr>
<th>Name</th>
<th>Type</th>
<th>Description</th>
</tr>
</thead>
<tbody>
<tr>
<td>name</td>
<td>String</td>
<td></td>
</tr>
<tr>
<td>fn</td>
<td>Function</td>
<td>A callback function that is called with options</td>
</tr>
</tbody>
</table>
<hr>
<p><a name="beforebulkupdate"></a></p>
<h2 id="beforebulkupdatename-fn"><code>beforeBulkUpdate(name, fn)</code></h2>
<p><a href="https://github.com/sequelize/sequelize/blob/3e5b8772ef75169685fc96024366bca9958fee63/lib/hooks.js#L342">View code</a></p>
<p>A hook that is run before updating instances in bulk</p>
<p><strong>Params:</strong></p>
<table>
<thead>
<tr>
<th>Name</th>
<th>Type</th>
<th>Description</th>
</tr>
</thead>
<tbody>
<tr>
<td>name</td>
<td>String</td>
<td></td>
</tr>
<tr>
<td>fn</td>
<td>Function</td>
<td>A callback function that is called with options</td>
</tr>
</tbody>
</table>
<hr>
<p><a name="afterbulkupdate"></a></p>
<h2 id="afterbulkupdatename-fn"><code>afterBulkUpdate(name, fn)</code></h2>
<p><a href="https://github.com/sequelize/sequelize/blob/3e5b8772ef75169685fc96024366bca9958fee63/lib/hooks.js#L349">View code</a></p>
<p>A hook that is run after updating instances in bulk</p>
<p><strong>Params:</strong></p>
<table>
<thead>
<tr>
<th>Name</th>
<th>Type</th>
<th>Description</th>
</tr>
</thead>
<tbody>
<tr>
<td>name</td>
<td>String</td>
<td></td>
</tr>
<tr>
<td>fn</td>
<td>Function</td>
<td>A callback function that is called with options</td>
</tr>
</tbody>
</table>
<hr>
<p><a name="beforefind"></a></p>
<h2 id="beforefindname-fn"><code>beforeFind(name, fn)</code></h2>
<p><a href="https://github.com/sequelize/sequelize/blob/3e5b8772ef75169685fc96024366bca9958fee63/lib/hooks.js#L356">View code</a></p>
<p>A hook that is run before a find (select) query</p>
<p><strong>Params:</strong></p>
<table>
<thead>
<tr>
<th>Name</th>
<th>Type</th>
<th>Description</th>
</tr>
</thead>
<tbody>
<tr>
<td>name</td>
<td>String</td>
<td></td>
</tr>
<tr>
<td>fn</td>
<td>Function</td>
<td>A callback function that is called with options</td>
</tr>
</tbody>
</table>
<hr>
<p><a name="beforefindafterexpandincludeall"></a></p>
<h2 id="beforefindafterexpandincludeallname-fn"><code>beforeFindAfterExpandIncludeAll(name, fn)</code></h2>
<p><a href="https://github.com/sequelize/sequelize/blob/3e5b8772ef75169685fc96024366bca9958fee63/lib/hooks.js#L363">View code</a></p>
<p>A hook that is run before a find (select) query, after any { include: {all: ...} } options are expanded</p>
<p><strong>Params:</strong></p>
<table>
<thead>
<tr>
<th>Name</th>
<th>Type</th>
<th>Description</th>
</tr>
</thead>
<tbody>
<tr>
<td>name</td>
<td>String</td>
<td></td>
</tr>
<tr>
<td>fn</td>
<td>Function</td>
<td>A callback function that is called with options</td>
</tr>
</tbody>
</table>
<hr>
<p><a name="beforefindafteroptions"></a></p>
<h2 id="beforefindafteroptionsname-fn"><code>beforeFindAfterOptions(name, fn)</code></h2>
<p><a href="https://github.com/sequelize/sequelize/blob/3e5b8772ef75169685fc96024366bca9958fee63/lib/hooks.js#L370">View code</a></p>
<p>A hook that is run before a find (select) query, after all option parsing is complete</p>
<p><strong>Params:</strong></p>
<table>
<thead>
<tr>
<th>Name</th>
<th>Type</th>
<th>Description</th>
</tr>
</thead>
<tbody>
<tr>
<td>name</td>
<td>String</td>
<td></td>
</tr>
<tr>
<td>fn</td>
<td>Function</td>
<td>A callback function that is called with options</td>
</tr>
</tbody>
</table>
<hr>
<p><a name="afterfind"></a></p>
<h2 id="afterfindname-fn"><code>afterFind(name, fn)</code></h2>
<p><a href="https://github.com/sequelize/sequelize/blob/3e5b8772ef75169685fc96024366bca9958fee63/lib/hooks.js#L377">View code</a></p>
<p>A hook that is run after a find (select) query</p>
<p><strong>Params:</strong></p>
<table>
<thead>
<tr>
<th>Name</th>
<th>Type</th>
<th>Description</th>
</tr>
</thead>
<tbody>
<tr>
<td>name</td>
<td>String</td>
<td></td>
</tr>
<tr>
<td>fn</td>
<td>Function</td>
<td>A callback function that is called with instance(s), options</td>
</tr>
</tbody>
</table>
<hr>
<p><a name="beforedefine"></a></p>
<h2 id="beforedefinename-fn"><code>beforeDefine(name, fn)</code></h2>
<p><a href="https://github.com/sequelize/sequelize/blob/3e5b8772ef75169685fc96024366bca9958fee63/lib/hooks.js#L384">View code</a></p>
<p>A hook that is run before a define call</p>
<p><strong>Params:</strong></p>
<table>
<thead>
<tr>
<th>Name</th>
<th>Type</th>
<th>Description</th>
</tr>
</thead>
<tbody>
<tr>
<td>name</td>
<td>String</td>
<td></td>
</tr>
<tr>
<td>fn</td>
<td>Function</td>
<td>A callback function that is called with attributes, options</td>
</tr>
</tbody>
</table>
<hr>
<p><a name="afterdefine"></a></p>
<h2 id="afterdefinename-fn"><code>afterDefine(name, fn)</code></h2>
<p><a href="https://github.com/sequelize/sequelize/blob/3e5b8772ef75169685fc96024366bca9958fee63/lib/hooks.js#L391">View code</a></p>
<p>A hook that is run after a define call</p>
<p><strong>Params:</strong></p>
<table>
<thead>
<tr>
<th>Name</th>
<th>Type</th>
<th>Description</th>
</tr>
</thead>
<tbody>
<tr>
<td>name</td>
<td>String</td>
<td></td>
</tr>
<tr>
<td>fn</td>
<td>Function</td>
<td>A callback function that is called with factory</td>
</tr>
</tbody>
</table>
<hr>
<p><a name="beforeinit"></a></p>
<h2 id="beforeinitname-fn"><code>beforeInit(name, fn)</code></h2>
<p><a href="https://github.com/sequelize/sequelize/blob/3e5b8772ef75169685fc96024366bca9958fee63/lib/hooks.js#L398">View code</a></p>
<p>A hook that is run before Sequelize() call</p>
<p><strong>Params:</strong></p>
<table>
<thead>
<tr>
<th>Name</th>
<th>Type</th>
<th>Description</th>
</tr>
</thead>
<tbody>
<tr>
<td>name</td>
<td>String</td>
<td></td>
</tr>
<tr>
<td>fn</td>
<td>Function</td>
<td>A callback function that is called with config, options</td>
</tr>
</tbody>
</table>
<hr>
<p><a name="afterinit"></a></p>
<h2 id="afterinitname-fn"><code>afterInit(name, fn)</code></h2>
<p><a href="https://github.com/sequelize/sequelize/blob/3e5b8772ef75169685fc96024366bca9958fee63/lib/hooks.js#L405">View code</a></p>
<p>A hook that is run after Sequelize() call</p>
<p><strong>Params:</strong></p>
<table>
<thead>
<tr>
<th>Name</th>
<th>Type</th>
<th>Description</th>
</tr>
</thead>
<tbody>
<tr>
<td>name</td>
<td>String</td>
<td></td>
</tr>
<tr>
<td>fn</td>
<td>Function</td>
<td>A callback function that is called with sequelize</td>
</tr>
</tbody>
</table>
<hr>
<p><a name="beforesync"></a></p>
<h2 id="beforesyncname-fn"><code>beforeSync(name, fn)</code></h2>
<p><a href="https://github.com/sequelize/sequelize/blob/3e5b8772ef75169685fc96024366bca9958fee63/lib/hooks.js#L412">View code</a></p>
<p>A hook that is run before Model.sync call</p>
<p><strong>Params:</strong></p>
<table>
<thead>
<tr>
<th>Name</th>
<th>Type</th>
<th>Description</th>
</tr>
</thead>
<tbody>
<tr>
<td>name</td>
<td>String</td>
<td></td>
</tr>
<tr>
<td>fn</td>
<td>Function</td>
<td>A callback function that is called with options passed to Model.sync</td>
</tr>
</tbody>
</table>
<hr>
<p><a name="aftersync"></a></p>
<h2 id="aftersyncname-fn"><code>afterSync(name, fn)</code></h2>
<p><a href="https://github.com/sequelize/sequelize/blob/3e5b8772ef75169685fc96024366bca9958fee63/lib/hooks.js#L419">View code</a></p>
<p>A hook that is run after Model.sync call</p>
<p><strong>Params:</strong></p>
<table>
<thead>
<tr>
<th>Name</th>
<th>Type</th>
<th>Description</th>
</tr>
</thead>
<tbody>
<tr>
<td>name</td>
<td>String</td>
<td></td>
</tr>
<tr>
<td>fn</td>
<td>Function</td>
<td>A callback function that is called with options passed to Model.sync</td>
</tr>
</tbody>
</table>
<hr>
<p><a name="beforebulksync"></a></p>
<h2 id="beforebulksyncname-fn"><code>beforeBulkSync(name, fn)</code></h2>
<p><a href="https://github.com/sequelize/sequelize/blob/3e5b8772ef75169685fc96024366bca9958fee63/lib/hooks.js#L426">View code</a></p>
<p>A hook that is run before sequelize.sync call</p>
<p><strong>Params:</strong></p>
<table>
<thead>
<tr>
<th>Name</th>
<th>Type</th>
<th>Description</th>
</tr>
</thead>
<tbody>
<tr>
<td>name</td>
<td>String</td>
<td></td>
</tr>
<tr>
<td>fn</td>
<td>Function</td>
<td>A callback function that is called with options passed to sequelize.sync</td>
</tr>
</tbody>
</table>
<hr>
<p><a name="afterbulksync"></a></p>
<h2 id="afterbulksync"><code>afterBulkSync</code></h2>
<p><a href="https://github.com/sequelize/sequelize/blob/3e5b8772ef75169685fc96024366bca9958fee63/lib/hooks.js#L434">View code</a></p>
<p>A hook that is run after sequelize.sync call</p>
<p><strong>Params:</strong></p>
<table>
<thead>
<tr>
<th>Name</th>
<th>Type</th>
<th>Description</th>
</tr>
</thead>
<tbody>
<tr>
<td>name</td>
<td>String</td>
<td></td>
</tr>
<tr>
<td>fn</td>
<td>Function</td>
<td>A callback function that is called with options passed to sequelize.sync</td>
</tr>
</tbody>
</table>
<hr>
<p><em>This document is automatically generated based on source code comments. Please do not edit it directly, as your changes will be ignored. Please write on <a href="irc://irc.freenode.net/#sequelizejs">IRC</a>, open an issue or a create a pull request if you feel something can be improved. For help on how to write source code documentation see <a href="http://usejsdoc.org">JSDoc</a> and <a href="https://github.com/tj/dox">dox</a></em></p>
              
            </div>
          </div>
          <footer>
  
    <div class="rst-footer-buttons" role="navigation" aria-label="footer navigation">
      
        <a href="/v3/api/transaction/" class="btn btn-neutral float-right" title="Transaction">Next <span class="icon icon-circle-arrow-right"></span></a>
      
      
        <a href="/v3/api/associations/belongs-to-many/" class="btn btn-neutral" title="BelongsToMany (n:m)"><span class="icon icon-circle-arrow-left"></span> Previous</a>
      
    </div>
  

  <hr>

  <div role="contentinfo">
    <!-- Copyright etc -->
    
  </div>

  Built with <a href="https://www.mkdocs.org/">MkDocs</a> using a <a href="https://github.com/snide/sphinx_rtd_theme">theme</a> provided by <a href="https://readthedocs.org">Read the Docs</a>.
</footer>
      
        </div>
      </div>

    </section>

  </div>

  <div class="rst-versions" role="note" aria-label="versions">
  <span class="rst-current-version" data-toggle="rst-current-version">
    
        <span>
          <a href="https://github.com/sequelize/sequelize/" class="fa fa-github" style="color: #fcfcfc"> GitHub</a>
        </span>
    
    
      <span><a href="/v3/api/associations/belongs-to-many/" style="color: #fcfcfc">« Previous</a></span>
    
    
      <span><a href="/v3/api/transaction/" style="color: #fcfcfc">Next »</a></span>
    
  </span>
</div>
    <script>var base_url = '../..';</script>
    <script src="/v3/js/theme_extra.js" defer=""></script>
    <script src="/v3/js/theme.js" defer=""></script>
      <script src="//cdnjs.cloudflare.com/ajax/libs/highlight.js/8.4/highlight.min.js" defer=""></script>
      <script src="/v3/search/main.js" defer=""></script>
    <script defer="">
        window.onload = function () {
            SphinxRtdTheme.Navigation.enable(true);
        };
    </script>



</body></html>